/*
 *  Copright: 2008 Philipp Leitner, Distributed Systems Group,
 *            TU Wien, leitner@infosys.tuwien.ac.at
 *
 *  This file is part of DAIOS.
 *
 *  DAIOS is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation.
 * 
 *  DAIOS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with DAIOS.  If not, see
 *  <http://www.gnu.org/licenses/>.
 * 
 */

package at.ac.tuwien.infosys.dsg.daiosPlugins.nativeInvoker;

import at.ac.tuwien.infosys.dsg.daios.framework.interfaces.IDaiosCallback;
import at.ac.tuwien.infosys.dsg.daios.framework.structs.DaiosOutputMessage;

/**
 * The (protected) callback handler used internally by the
 * Daios native framework to do Poll Object calls. 
 * 
 * @author philipp
 *
 */
class NativeCallbackHandler implements IDaiosCallback {
	
	private NativePollObject po = null;
	
	/**
	 * Protected constructor. Create a new callback handler
	 * wrapped around a PollObject.
	 * 
	 * @param po The Poll Object that is going to be notified
	 * when the callback handler receives a result.
	 */
	protected NativeCallbackHandler(NativePollObject po) {
		this.po = po;
	}
	
	/**
	 * This is the callback method that will get notified
	 * when the invocation ended <i>successfully</i>. In
	 * that case the handler will notify the wrapped Poll
	 * Object.
	 * 
	 * @param output The result of the successful
	 * invocation.
	 */
	public void onComplete(DaiosOutputMessage output) {
		po.setResult(output);
	}

	/**
	 * This is the callback method that will get notified
	 * when the invocation ended <i>unsuccessfully</i>, i.e.
	 * with an error. The handler will notify the wrapped Poll
	 * object about the error. 
	 * 
	 * @param e The exception that has been thrown in the course
	 * of the invocation.
	 */	
	public void onError(Exception e) {
		po.setError(e);
	}

}
